<template>
  <div>
    <!-- 头部栏 -->
    <div class="Header_bar">
      <van-search show-action v-model="value" placeholder="请输入小区或地址">
        <template #label>
          <div class="Header_bar_box" @click="$router.push('/city')">
            <p>{{ $store.state.mycity }}</p>
            <van-icon name="arrow-down" />
          </div>
        </template>
        <template #left>
          <van-icon
            name="arrow-left"
            color="#fff"
            size="20px"
            @click="$router.push('/')"
          />
        </template>
        <template #action>
          <div @click="$router.push('/map')">
            <van-icon size="25" color="#fff" />
            <span class="icon-ditu iconfont"></span>
          </div>
        </template>
      </van-search>
    </div>
    <!-- 选地区 -->
    <van-dropdown-menu>
      <van-dropdown-item title="区域">
        <van-picker
          show-toolbar
          :columns="list"
          value-key="label"
          @confirm="onConfirm"
        />
      </van-dropdown-item>
      <van-dropdown-item title="方式">
        <van-picker show-toolbar :columns="rentType" value-key="label" />
      </van-dropdown-item>
      <van-dropdown-item title="租房">
        <van-picker show-toolbar :columns="price" value-key="label" />
      </van-dropdown-item>
      <!-- title="筛选" direction="up" -->
      <van-dropdown-item
        title="筛选"
        @open="show = true"
        @close="show = false"
      />
      <van-popup
        v-model="show"
        :overlay="false"
        position="right"
        :style="{ width: '80%', height: '100%' }"
      >
        <div class="saixuan">
          <h3>户型</h3>
          <div class="saixuan-boxs">
            <div
              class="saixuan-box"
              :class="'saixuan_box_style'"
              v-for="(itme, index) in roomType"
              :key="index"
            >
              {{ itme.label }}
            </div>
          </div>
        </div>
        <div class="saixuan">
          <h3>朝向</h3>
          <div class="saixuan-boxs">
            <div
              class="saixuan-box"
              :class="'saixuan_box_style'"
              v-for="(itme, index) in oriented"
              :key="index"
            >
              {{ itme.label }}
            </div>
          </div>
        </div>
        <div class="saixuan">
          <h3>楼房</h3>
          <div class="saixuan-boxs">
            <div
              class="saixuan-box"
              :class="'saixuan_box_style'"
              v-for="(itme, index) in floor"
              :key="index"
            >
              {{ itme.label }}
            </div>
          </div>
        </div>
        <div class="saixuan">
          <h3>房屋亮点</h3>
          <div class="saixuan-boxs">
            <div
              class="saixuan-box"
              :class="'saixuan_box_style'"
              v-for="(itme, index) in characteristic"
              :key="index"
            >
              {{ itme.label }}
            </div>
          </div>
        </div>
        <div class="xuanzhe">
          <button class="qx">取消</button>
          <button class="qr">确认</button>
        </div>
      </van-popup>
    </van-dropdown-menu>
    <!-- 展示区 -->
    <div class="zhanshi">
      <div class="imges"><img src="" alt="" /></div>
      <div class="text sin-line">
        <h3 class="sin-line">fffs</h3>
        <p class="sin-line">二室/85/南/平江路49弄</p>
        <div class="box"><span class="box1">地铁站</span></div>
        <span class="money">1000<i class="i">元/月</i></span>
      </div>
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'
import { Toast } from 'vant'
export default {
  name: 'hk-findroom',
  mounted() {},

  data() {
    return {
      active: 0,
      value: '',
      show: false,
      areaList: {
        province_list: {
          110000: '北京市',
          120000: '天津市'
        },
        city_list: {
          110100: '北京市',
          120100: '天津市'
        },
        county_list: {
          110101: '东城区',
          110102: '西城区'
          // ....
        }
      },
      list: [],
      rentType: '',
      price: '',
      roomType: '',
      oriented: '',
      floor: '',
      characteristic: '',
      parameters: {
        cityId: '',
        area: '',
        subway: '',
        rentType: true,
        price: null,
        more: '',
        roomType: '',
        oriented: '',
        characteristic: '',
        floor: '',
        start: 1,
        end: 20
      }
    }
  },
  async created() {
    const idValue = JSON.parse(localStorage.getItem('city')).value

    const res = await request({
      url: '/houses/condition',
      method: 'get',
      params: {
        id: idValue
      }
    })
    console.log(res)
    const {
      area,
      subway,
      rentType,
      price,
      roomType,
      oriented,
      floor,
      characteristic
    } = res.body
    this.list.push(area)
    this.list.push(subway)
    this.list.forEach((item) => {
      item.children[0].children = [{ label: '' }]
    })
    this.rentType = rentType
    this.price = price
    // 筛选
    this.roomType = roomType
    this.oriented = oriented
    this.floor = floor
    this.characteristic = characteristic
    console.log(this.list)
    console.log(this.price)
    console.log(this.rentType)
  },
  methods: {
    onConfirm(value, index) {
      Toast(`当前值：${value}, 当前索引：${index}`)
    }
  },
  computed: {
    // deepClone(newObj, oldObj = this.list) {
    //   for (const key in oldObj) {
    //     if (Object.prototype.toString.call(oldObj[key]) === '[object Object]') {
    //       newObj[key] = {}
    //       this.deepClone(newObj[key], oldObj[key])
    //     } else if (
    //       Object.prototype.toString.call(oldObj[key]) === '[object Array]'
    //     ) {
    //       newObj[key] = []
    //       this.fn(newObj[key], oldObj[key])
    //     } else {
    //       // if (key === 'value') {
    //       //   newObj.text = oldObj[key]
    //       // } else {
    //       newObj[key] = oldObj[key]
    //       // }
    //     }
    //   }
    //   return newObj
    // }
  }
}
</script>

<style scoped lang="less">
// 头部栏
.van-search {
  background-color: #21b97a;
  padding: 10px 20px 10px 7px;
}
.van-search__content {
  padding-left: 8px;
}
.van-icon-arrow-left:before {
  margin-right: 8px;
}
.Header_bar_box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  p {
    margin-right: 5px;
  }
}
.icon-ditu {
  font-size: 32px;
  color: #fff;
  line-height: 20px;
}
.van-search__action {
  line-height: 0;
  padding: 5px;
  padding-right: 0;
}
/deep/.van-field__left-icon {
  border-left: 1px solid #e3e3e3;
  // height: ;
}
/deep/.van-icon-search:before {
  padding-left: 6px;
}
// 选地区
/deep/.van-picker__toolbar {
  position: absolute;
  bottom: 0;
  z-index: 2;
  width: 100vw;
  .van-picker__cancel {
    width: 40%;
    border-top: 1px solid #e9e9e9;
    color: #000;
  }
  .van-picker__confirm {
    width: 60%;
    background-color: #21b97a;
    color: #fff;
  }
}
// 筛选
.van-popup {
  margin-top: -1px;
  .saixuan {
    padding: 0 15px;
    width: 100%;
    h3 {
      font-size: 15px;
      color: #000;
      font-weight: normal;
      margin: 20px 0;
    }
    .saixuan-boxs {
      display: flex;
      // justify-content: space-between;
      flex-wrap: wrap;
      margin-left: 40px;
      padding-bottom: 10px;
      border-bottom: 1px solid #e5e5e5;
      .saixuan-box {
        margin: 0 15px 18px 0;
        width: 70px;
        height: 32px;
        border: 1px solid #dddddd;
        font-size: 12px;
        text-align: center;
        line-height: 32px;
      }
    }
  }
  .xuanzhe {
    position: sticky;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 45px;
    display: flex;
    margin-bottom: 1px;
    .qx {
      width: 40%;
    }
    .qr {
      flex: 1;
      background-color: #21b97a;
      color: #fff;
    }
  }
}
// 选择时的样式
.saixuan_box_style {
  border: 1px solid #21b97a !important;
  background-color: #defaef;
  color: #21b97a;
}
// 展示区
.zhanshi {
  height: 120px;
  margin: 10px 20px 0;
  border-bottom: 1px solid #e9e9e9;
  display: flex;
  align-items: center;
  .imges {
    width: 100px;
    height: 80px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .text {
    flex: 1;
    height: 100%;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    h3 {
      font-size: 15px;
      color: #3c4346;
    }
    p {
      font-size: 12px;
      color: rgb(159, 158, 158);
    }
    .box {
      .box1 {
        padding: 4px;
        font-size: 12px;
        background-color: #e1f5f8;
        color: #6fcfda;
      }
    }
    .money {
      font-weight: 700;
      font-size: 16px;
      color: red;
      padding-top: 5px;
      .i {
        margin-left: 3px;
        font-weight: normal;
        font-size: 12px;
      }
    }
  }
}
</style>
